package com.dcm.groupbuy.controller;

import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.common.utils.IdWorker;
import com.dcm.common.vo.CommonResponse;
import com.dcm.groupbuy.bo.OrderBo;
import com.dcm.groupbuy.entity.GroupBuyEntity;
import com.dcm.groupbuy.service.OrderBoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 牛浩
 */
@Api(tags = "OrderBo")
@RestController
@CrossOrigin
@RequestMapping("/OrderBo")
@EnableResponseBodyAdvice
public class OrderBoController {
    @Autowired
    private OrderBoService orderboService;

    /**
     * 参加拼团
     * @param id
     * @param name
     */
    @ApiOperation("参加拼团")
    @GetMapping("/startGroup")
    public CommonResponse startGroup(@RequestParam(value = "id",required = false) Long id, @RequestParam(value = "name",required = false)String name){
        return orderboService.startGroup(id,name);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @ApiOperation("根据id查询")
    @GetMapping("/findById")
    public OrderBo findById(@RequestParam(value = "id",required = false) Long id){
        return orderboService.findById(id);
    }

    /**
     * 单独购买
     * @param note
     * @param memberUsername
     */
    @ApiOperation("单独购买")
    @GetMapping("/mySeIf")
    public void mySeIf(@RequestParam("note") String note,@RequestParam("memberUsername")String memberUsername){
        orderboService.mySeIf(note,memberUsername);
    }
    @ApiOperation("分页")
    @GetMapping("/findPage")
    public PageInfo<OrderBo> findPage(@RequestParam(value = "currentPage", required = false) Integer currentPage,
                                             @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return orderboService.findPage(currentPage, pageSize);
    }
}
